package com.sto.stoapp.activity.aviation;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.adapter.SoleAdapter;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.entity.FunctionEntity;
import com.sto.stoapp.listener.StoOnItemClickListener;
import com.sto.stoapp.widget.StoHomeActivity;

import java.util.ArrayList;
import java.util.List;

public class StoAviationSendPieceActivity extends StoHomeActivity {

    // 按键映射
    private static final int[] MAPP_TO_KEY = { R.string.send_piece_by_route,
            R.string.send_piece_by_des };
    private ListView RecvFuncList;
    private SoleAdapter RecvListAdapter;
    private String busiType = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sto_sales_received_piece);
        this.setTitleBottom(R.string.send_piece,
                HomeBroadAction.AVIATION_SCANNER_BROAD);
        Bundle extras = getIntent().getExtras();
        busiType = extras.getString("busiType");
        initWidget();
    }

    private void initWidget() {
        RecvFuncList = (ListView) findViewById(R.id.receivedFunc_list);
        RecvListAdapter = new SoleAdapter(this, getResourceList());
        RecvFuncList.setAdapter(RecvListAdapter);

        RecvFuncList.setOnItemClickListener(new StoOnItemClickListener(this) {

            @Override
            public void KcOnItemClickListener(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                arg1.setSelected(true);
                TextView title = (TextView) arg1.findViewById(R.id.res_test);
                clickItemEvent(title.getText().toString());
            }

        });

    }

    private void clickItemEvent(String title) {
        // 指定路由发件
        if (title.equals(getText(R.string.send_piece_by_route))) {
            Intent intent = new Intent(this, StoSendPieceByRouteActivity.class);
            intent.putExtra("busiType", busiType);
            startActivity(intent);
        }
        // 指定目的地发件
        else if (title.equals(getText(R.string.send_piece_by_des))) {
            Intent intent = new Intent(this, StoSendPieceByDesActivity.class);
            intent.putExtra("busiType", busiType);
            startActivity(intent);
        } else {

        }
    }

    private List<FunctionEntity> getResourceList() {
        List<String> resList = new ArrayList<String>();
        resList.add(getText(R.string.send_piece_by_route).toString());
        resList.add(getText(R.string.send_piece_by_des).toString());
        List<FunctionEntity> functionList = new ArrayList<FunctionEntity>();
        for (String res : resList) {
            FunctionEntity entity = new FunctionEntity();
            entity.setTitle(res);
            functionList.add(entity);
        }
        return functionList;
    }





}
